⏱️ Do It Now
Create a OneNote Page and copy this into the title:
Lesson 2 - Spring 2 - Working With Variables
Complete this and screenshot it into OneNote
⌨️ Setting Up For Today
Click this link: VSCODEEDU.COM
- Sign In with your Microsoft Account
- Create a New project and call it Y8 - SP2.2 - Variables
- Rename main.py as Activity 1.py
Copy the table below into OneNote
Share your project and paste the link into the table
|
📝 Link To My Project |
|
Paste a link to your project Python Lesson SP2.1 below: |
🎯 Learning Objectives
- LO1: Learning what variables are and why they are used within programming
- LO2: Learning how to create a variable, assign a value to it and output it within an fString
- LO3: Learning how to prompt a user to enter a value through the input function, and how this can be assigned to a variable
⌨️ Create a Variable
Copy and paste this comment above the activity you are about to complete
# 🐍 Coding Activity 1 - Variables
📖 Instructions
- We are going to make a variable called username
- Variables allow us to store data that can be accessed at any future point in the program
- The name of a variable must be unique and contain no spaces
Paste this code into your program
# The code below creates a variable.
# The value on the right of the equals sign is being
# assigned(given) to the variable.
username = "bob"
🐍 Outputting Variables in an fString
📖 Explanation
- The code below uses the print() function to output an fString
- fStrings allow us to include calculations or variables as part of an output string of text
- Remember!
- The string must have an f in front of it
- Calculations or variables must be placed within {curly brackets}
Copy and paste this code into your program
# Outputting a variable within an fString
# It must begin with an f
# Variables must be inside {curly brackets}
print(f"Hello {username}. It is nice to meet you!")
Extension Activity
- Create another variable called place
- Assign the name of a place
- Output an fString that includes the place along with a suitable message
- Make sure you explain your code with suitable comments
LO1 - Reflection Task
Complete this and screenshot it into OneNote
LO1 Reflection Task
Click reuse if it doesn't show
🐍 Coding Activity 2
Create a new python file called Activity 2.py
Copy this comment and paste it above the activity you are about to complete
# 🐍 Activity 2 - Inputs and Variables
🐍 Assigning an Input to a Variable
We will now learn how to create a user input and assign it to a variable
- A new variable called food will be created
- A user input will be assigned (given) to the variable
- The input contains a prompt (message) that tells the user what to do
Add the following code to your program
# The code below assigns a user input to a variable
# The text string in the brackets is a prompt (telling the user what to do)
food = input("Type the name of your favourite food: ")
🐍 Outputting the value of a variable in an fString
We will now output the variable within an fString
Add the following code to a new line of your program
# The code below uses an fString to output the value of the variable
# The variable is placed in the curly brackets
print(f"Wow, I really like {food} as well.")
🐍 Simulate A Conversation
It's now your turn to create a virtual conversation!
Your program should behave like this...
You must ensure you use a different variable for each question
Welcome to PopCulture ChatBot!
What is your name?
> Mia
Hi Mia! Nice to meet you.
What is your favourite TV show??
> Friends
Wow, I like watching friends as well
What is your favourite snack??
> Doritos
Cool, nothing beats watching Friends and eating Doritos
Where would you like to travel to?
> New Zealand
Wow, It would be great to visit New Zealand, but don't forget to pack Doritos (in case they don't have any)!
Extension Activity
- Use an fString in the input prompt, to make the questions more targeted
colour = input(f"{username}, what is your favourite colour?")
Copy and paste this table into your OneNote Page
|
💯 Wayground Quiz |
|
Click this link: https://wayground.com/join/quiz/69a4bc21b3310e0c2d8f86a5/start?from=admin&preview=true Paste your score below: |